﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Messaging;

namespace ServiceController
{
    public delegate DataAccess.DataAccessResult GetHostServicePropertyDelegate(String SubscriptionID, String CertificatePath, String ServiceName, bool EmbedDetail);

    public partial class ServiceController
    {
        GetHostServicePropertyDelegate _GetHostServicePropertyDelegate;

        

        public void GetHostServicePropertyAsync(String SubscriptionID, String CertificatePath, String ServiceName, bool EmbedDetail, object UserState)
        {
            _GetHostServicePropertyDelegate.BeginInvoke(SubscriptionID, CertificatePath, ServiceName, EmbedDetail,
                new AsyncCallback(GetHostServicePropertyCallBack), UserState);
        }

        void GetHostServicePropertyCallBack(IAsyncResult ar)
        {
            AsyncResult aresult = (AsyncResult)ar;
            DataAccess.DataAccessResult result = _GetHostServicePropertyDelegate.EndInvoke(ar);
            OnGetHostServicePropertyCompleted(new ServiceControllerEventArgs()
            {
                HostServiceProperty = result.ServiceProperty,
                error = result.Error,
                UserState = ar.AsyncState,
                IsOperationSuccessful = result.IsOperationSuccessful,
            });
        }

        private DataAccess.DataAccessResult GetHostServiceProperty(String SubscriptionID, String CertificatePath, String ServiceName, bool EmbedDetail)
        {
            return da.GetHostServiceProperty(SubscriptionID, CertificatePath, ServiceName, EmbedDetail);

            //Entities.HostedServiceProperty serviceProperty = new Entities.HostedServiceProperty();
            //DataAccess.DataAccess da = new DataAccess.DataAccess();

            //try
            //{
            //    serviceProperty = da._GetHostServiceProperty(SubscriptionID, CertificatePath, ServiceName);
            //    OnGetHostServicePropertyCompleted(new ServiceControllerEventArgs() { HostServiceProperty = serviceProperty });

            //}
            //catch (Exception ex)
            //{
            //    OnGetHostServicePropertyCompleted(new ServiceControllerEventArgs() { error = ex });
            //}
        }
    }
}
